home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / wemdemo4.zip / INFO / ELISP.15 < prev    next >
Text File  |  1994-09-21  |  49KB  |  1,136 lines

  1. Info file elisp, produced by Makeinfo, -*- Text -*- from input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual,   for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts
  10. Avenue,  Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of
  15. this manual provided the copyright notice and this permission notice
  16. are preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28.  
  29. 
  30. File: elisp,  Node: Rename or Copy,  Next: Numbered Backups,  Prev: Making Backups,  Up: Backup Files
  31.  
  32. Backup by Renaming or by Copying?
  33. ---------------------------------
  34.  
  35.    There are two ways that Emacs can make a backup file:
  36.  
  37.    * Emacs can rename the original file so that it becomes a backup
  38.      file, and then write the buffer being saved into a new file.  In
  39.      this case, any other names (i.e., hard links) of the original
  40.      file will now refer to the backup file.  The new file will be
  41.      owned by the user doing the editing, and its group will be the
  42.      default for the user or the directory.
  43.  
  44.    * Emacs can copy the original file into a backup file, and then
  45.      overwrite the original file with new contents.  In this case,
  46.      any other names (i.e., hard links) of the original file will
  47.      still refer to the current version of the file.  The file's
  48.      owner and group will be unchanged.
  49.  
  50.    The first method, renaming, is the default.
  51.  
  52.    The variable `backup-by-copying', if non-`nil', says to use the
  53. second method, which is to copy the original file and overwrite it
  54. with the new buffer contents.  The variable `file-precious-flag', if
  55. non-`nil', also has this effect (as a sideline of its main
  56. significance).  *Note Saving Buffers::.
  57.  
  58.    The variables `backup-by-copying-when-linked' and
  59. `backup-by-copying-when-mismatch', if non-`nil', cause the second
  60. method to be used in certain special cases.  They have no effect on
  61. the treatment of files that don't fall into the special cases.
  62.  
  63.  * Variable: backup-by-copying
  64.      This variable controls whether to make backup files by copying. 
  65.      If it is non-`nil', then Emacs always copies the current
  66.      contents of the file into the backup file before writing the
  67.      buffer to be saved to the file.  (In many circumstances, this
  68.      has the same effect as `file-precious-flag'.)
  69.  
  70.  * Variable: backup-by-copying-when-linked
  71.      This variable controls whether to make backups by copying for
  72.      files with multiple names (hard links).  If it is non-`nil',
  73.      then Emacs will use copying to create backups for those files.
  74.  
  75.      This variable is significant only if `backup-by-copying' is
  76.      `nil', since copying is always used when that variable is
  77.      non-`nil'.
  78.  
  79.  * Variable: backup-by-copying-when-mismatch
  80.      This variable controls whether to make backups by copying when
  81.      renaming would cause either the owner or the group of the file
  82.      to change.  If it is non-`nil' then Emacs will create backups by
  83.      copying in such cases.
  84.  
  85.      The value has no effect when renaming would not result in
  86.      changing the owner or group of the file; that is, for files
  87.      which are owned by the user and whose group matches the default
  88.      for a new file created there by the user.
  89.  
  90.      This variable is significant only if `backup-by-copying' is
  91.      `nil', since copying is always used when that variable is
  92.      non-`nil'.
  93.  
  94.  
  95. 
  96. File: elisp,  Node: Numbered Backups,  Next: Backup Names,  Prev: Rename or Copy,  Up: Backup Files
  97.  
  98. Making and Deleting Numbered Backup Files
  99. -----------------------------------------
  100.  
  101.    If a file's name is `foo', the names of its numbered backup
  102. versions are `foo.~V~', for various integers V, like this: `foo.~1~',
  103. `foo.~2~', `foo.~3~', ..., `foo.~259~', and so on.
  104.  
  105.  * User Option: version-control
  106.      This variable controls whether to make a single non-numbered
  107.      backup file or multiple numbered backups.
  108.  
  109.     `nil'
  110.           Make numbered backups if the visited file already has
  111.           numbered backups; otherwise, do not.
  112.  
  113.     `never'
  114.           Do not make numbered backups.
  115.  
  116.     ANYTHING ELSE
  117.           Do make numbered backups.
  118.  
  119.    The use of numbered backups ultimately leads to a large number of
  120. backup versions, which must then be deleted.  Emacs can do this
  121. automatically.
  122.  
  123.  * User Option: kept-new-versions
  124.      The value of this variable is the number of oldest versions to
  125.      keep when a new numbered backup is made.  The newly made backup
  126.      is included in the count.  The default value is 2.
  127.  
  128.  * User Option: kept-old-versions
  129.      The value of this variable is the number of oldest versions to
  130.      keep when a new numbered backup is made.  The default value is 2.
  131.  
  132.  * User Option: dired-kept-versions
  133.      This variable plays a role in Dired's `dired-clean-directory'
  134.      (`.') command like that played by `kept-old-versions' when a
  135.      backup file is made.  The default value is 2.
  136.  
  137.    If there are backups numbered 1, 2, 3, 5, and 7, and both of these
  138. variables have the value 2, then the backups numbered 1 and 2 will be
  139. kept as old versions and those numbered 5 and 7 will be kept as new
  140. versions; backup version 3 will be deleted.  The function
  141. `find-backup-file-name' is responsible for determining which backup
  142. versions to delete, but does not delete them itself.
  143.  
  144.  * User Option: trim-versions-without-asking
  145.      If this variable is non-`nil', then excess backup versions are
  146.      deleted silently.  Otherwise, the user is asked whether to
  147.      delete them.
  148.  
  149.  
  150. 
  151. File: elisp,  Node: Backup Names,  Prev: Numbered Backups,  Up: Backup Files
  152.  
  153. Naming Backup Files
  154. -------------------
  155.  
  156.    The functions in this section are documented mainly because you
  157. can customize the naming conventions for backup files by redefining
  158. them.
  159.  
  160.  * Function: backup-file-name-p FILENAME
  161.      This function returns a non-`nil' value if FILENAME is a
  162.      possible name for a backup file.  A file with the name FILENAME
  163.      need not exist; the function just checks the name.
  164.  
  165.           (backup-file-name-p "foo")
  166.                => nil
  167.           (backup-file-name-p "foo~")
  168.                => 3
  169.  
  170.      The standard definition of this function is as follows:
  171.  
  172.           (defun backup-file-name-p (file)
  173.             "Return non-nil if FILE is a backup file name (numeric or not)..."
  174.             (string-match "~$" file))
  175.  
  176.      Thus, the function returns a non-`nil' value if the file name
  177.      ends with a `~'
  178.  
  179.      This simple expression is placed in a separate function to make
  180.      it easy to redefine for customization.
  181.  
  182.  * Function: make-backup-file-name FILENAME
  183.      This function returns a string which is the name to use for a
  184.      non-numbered backup file for file FILENAME.  On Unix, this is
  185.      just FILENAME with a tilde appended.
  186.  
  187.      The standard definition of this function is as follows:
  188.  
  189.           (defun make-backup-file-name (file)
  190.             "Create the non-numeric backup file name for FILE..."
  191.             (concat file "~"))
  192.  
  193.      You can change the backup file naming convention by redefining
  194.      this function.  In the following example,
  195.      `make-backup-file-name' is redefined to prepend a `.' as well as
  196.      to append a tilde.
  197.  
  198.           (defun make-backup-file-name (filename)
  199.             (concat "." filename "~"))
  200.           
  201.           (make-backup-file-name "backups.texi")
  202.                => ".backups.texi~"
  203.  
  204.      If you do redefine `make-backup-file-name', be sure to redefine
  205.      `backup-file-name-p' and `find-backup-file-name' as well.
  206.  
  207.  * Function: find-backup-file-name FILENAME
  208.      This function computes the file name for a new backup file for
  209.      FILENAME.  It may also propose certain existing backup files for
  210.      deletion.  `find-backup-file-name' returns a list whose CAR is
  211.      the name for the new backup file and whose CDR is a list of
  212.      backup files whose deletion is proposed.
  213.  
  214.      Two variables called `kept-old-versions' and `kept-new-versions'
  215.      determine which old backup versions will be kept (by excluding
  216.      them from the list of backup files ripe for deletion).  *Note
  217.      Numbered Backups::.
  218.  
  219.      In this example, `~rms/foo.~5~' is the name to use for the new
  220.      backup file, and `~rms/foo.~3~' is an "excess" version that the
  221.      caller should consider deleting now.
  222.  
  223.           (find-backup-file-name "~rms/foo")
  224.                => ("~rms/foo.~5~" "~rms/foo.~3~")
  225.  
  226.  
  227. 
  228. File: elisp,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
  229.  
  230. Auto-Saving
  231. ===========
  232.  
  233.    Emacs periodically saves all files that you are visiting; this is
  234. called "auto-saving".  Auto-saving prevents you from losing more than
  235. a limited amount of work if the system crashes.  By default,
  236. auto-saves happen every 300 keystrokes.  *Note Auto-Save:
  237. (emacs)Auto-Save, for information on auto-save for users.  Here we
  238. describe the functions used to implement auto-saving and the
  239. variables that control them.
  240.  
  241.  * Variable: buffer-auto-save-file-name
  242.      This buffer-local variable is the name of the file used for
  243.      auto-saving the current buffer.  It is `nil' if the buffer
  244.      should not be auto-saved.
  245.  
  246.           buffer-auto-save-file-name
  247.           => "/xcssun/users/rms/lewis/#files.texi#"
  248.  
  249.  * Command: auto-save-mode ARG
  250.      When used interactively without an argument, this command is a
  251.      toggle switch: it turns on auto-saving of the current buffer if
  252.      it is off, and vice-versa.  With an argument ARG, the command
  253.      turns auto-saving on if the value of ARG is `t', a nonempty
  254.      list, or a positive integer.  Otherwise, it turns auto-saving off.
  255.  
  256.  * Function: auto-save-file-name-p FILENAME
  257.      This function returns a non-`nil' value if FILENAME is a string
  258.      that could be the name of an auto-save file.  It works based on
  259.      knowledge of the naming convention for auto-save files: a name
  260.      that begins and ends with hash marks (`#') is a possible
  261.      auto-save file name.  The argument FILENAME should not contain a
  262.      directory part.
  263.  
  264.           (make-auto-save-file-name)
  265.                => "/xcssun/users/rms/lewis/#files.texi#"
  266.           (auto-save-file-name-p "#files.texi#")
  267.                => 0
  268.           (auto-save-file-name-p "files.texi")
  269.                => nil
  270.  
  271.      The standard definition of this function is as follows:
  272.  
  273.           (defun auto-save-file-name-p (filename)
  274.             "Return non-nil if FILENAME can be yielded by..."
  275.             (string-match "^#.*#$" filename))
  276.  
  277.      This function exists so that you can customize it if you wish to
  278.      change the naming convention for auto-save files.  If you
  279.      redefine it, be sure to redefine `make-auto-save-file-name'
  280.      correspondingly.
  281.  
  282.  * Function: make-auto-save-file-name
  283.      This function returns the file name to use for auto-saving the
  284.      current buffer.  This is just the file name with hash marks
  285.      (`#') appended and prepended to it.  This function does not look
  286.      at the variable `auto-save-visited-file-name'; that should be
  287.      checked before this function is called.
  288.  
  289.           (make-auto-save-file-name)
  290.                => "/xcssun/users/rms/lewis/#backup.texi#"
  291.  
  292.      The standard definition of this function is as follows:
  293.  
  294.           (defun make-auto-save-file-name ()
  295.             "Return file name to use for auto-saves of current buffer..."
  296.             (if buffer-file-name
  297.                 (concat (file-name-directory buffer-file-name)
  298.                         "#"
  299.                         (file-name-nondirectory buffer-file-name)
  300.                         "#")
  301.               (expand-file-name (concat "#%" (buffer-name) "#"))))
  302.  
  303.      This exists as a separate function so that you can redefine it
  304.      to customize the naming convention for auto-save files.  Be sure
  305.      to change `auto-save-file-name-p' in a corresponding way.
  306.  
  307.  * Variable: auto-save-visited-file-name
  308.      If this variable is non-`nil', Emacs will auto-save buffers in
  309.      the files they are visiting.  That is, the auto-save is done in
  310.      the same file which you are editing.  Normally, this variable is
  311.      `nil', so auto-save files have distinct names that are created
  312.      by `make-auto-save-file-name'.
  313.  
  314.      When you change the value of this variable, the value does not
  315.      take effect until the next time auto-save mode is reenabled in
  316.      any given buffer.  If auto-save mode is already enabled,
  317.      auto-saves continue to go in the same file name until
  318.      `auto-save-mode' is called again.
  319.  
  320.  * Function: recent-auto-save-p
  321.      This function returns `t' if the current buffer has been
  322.      auto-saved since the last time it was read in or saved.
  323.  
  324.  * Function: set-buffer-auto-saved
  325.      This function marks the current buffer as auto-saved.  The
  326.      buffer will not be auto-saved again until the buffer text is
  327.      changed again.  The function returns `nil'.
  328.  
  329.  * User Option: auto-save-interval
  330.      The value of this variable is the number of characters that
  331.      Emacs reads from the keyboard between auto-saves.  Each time
  332.      this many more characters are read, auto-saving is done for all
  333.      buffers in which it is enabled.
  334.  
  335.  * User Option: auto-save-default
  336.      If this variable is non-`nil', buffers that are visiting files
  337.      have auto-saving enabled by default.  Otherwise, they do not.
  338.  
  339.  * Command: do-auto-save &optional NO-MESSAGE
  340.      This function auto-saves all buffers that need to be auto-saved.
  341.      This is all buffers for which auto-saving is enabled and that
  342.      have been changed since the last time they were auto-saved.
  343.  
  344.      Normally, if any buffers are auto-saved, a message
  345.      `Auto-saving...' is displayed in the echo area while auto-saving
  346.      is going on.  However, if NO-MESSAGE is non-`nil', the message
  347.      is inhibited.
  348.  
  349.  * Function: delete-auto-save-file-if-necessary
  350.      This function deletes the auto-save file for the current buffer
  351.      if variable `delete-auto-save-files' is non-`nil'.  It is called
  352.      every time a buffer is saved.
  353.  
  354.  * Variable: delete-auto-save-files
  355.      This variable is used by the function
  356.      `delete-auto-save-file-if-necessary'.  If it is non-`nil', Emacs
  357.      will delete auto-save files when a true save is done (in the
  358.      visited file).  This saves on disk space and unclutters your
  359.      directory.
  360.  
  361.  * Function: rename-auto-save-file
  362.      This function adjusts the current buffer's auto-save file name
  363.      if the visited file name has changed.  It also renames an
  364.      existing auto-save file.  If the visited file name has not
  365.      changed, this function does nothing.
  366.  
  367.  
  368. 
  369. File: elisp,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
  370.  
  371. Reverting
  372. =========
  373.  
  374.    If you have made extensive changes to a file and then change your
  375. mind about them, you can get rid of them by reading in the previous
  376. version of the file with the `revert-buffer' command.  *Note :
  377. (emacs)Reverting.
  378.  
  379.  * Command: revert-buffer &optional NO-AUTO-SAVE-OFFER-P NOCONFIRM
  380.      This command replaces the buffer text with the text of the
  381.      visited file on disk.  This action undoes all changes since the
  382.      file was visited or saved.
  383.  
  384.      When the value of the NO-AUTO-SAVE-OFFER-P argument is `nil',
  385.      and the latest auto-save file is more recent than the visited
  386.      file, `revert-buffer' asks the user whether to use that instead.
  387.      Otherwise, it always uses the latest backup file.  This argument
  388.      is the numeric prefix argument when the function is called
  389.      interactively.
  390.  
  391.      When the value of the NOCONFIRM argument is non-`nil',
  392.      `revert-buffer' does not ask for confirmation for the reversion
  393.      action.  This means that the buffer contents are deleted and
  394.      replaced by the text from the file on the disk, with no further
  395.      opportunities for the user to prevent it.
  396.  
  397.      Since reverting works by deleting the entire text of the buffer
  398.      and inserting the file contents, all the buffer's markers are
  399.      relocated to point at the beginning of the buffer.  This is not
  400.      "correct", but then, there is no way to determine what would be
  401.      correct.  It is not possible to determine, from the text before
  402.      and after, which characters after reversion correspond to which
  403.      characters before.
  404.  
  405.      If the value of the `revert-buffer-function' variable is
  406.      non-`nil', it is called as a function with no arguments to do
  407.      the work.
  408.  
  409.  * Variable: revert-buffer-function
  410.      The value of this variable is the function to use to revert this
  411.      buffer; but if the value of this variable is `nil', then the
  412.      `revert-buffer' function carries out its default action.  Modes
  413.      such as Dired mode, in which the text being edited does not
  414.      consist of a file's contents but can be regenerated in some
  415.      other fashion, give this variable a buffer-local value that is a
  416.      function to regenerate the contents.
  417.  
  418.  * Command: recover-file FILENAME
  419.      This function visits FILENAME, but gets the contents from its
  420.      last auto-save file.  This is useful after the system has
  421.      crashed, to resume editing the same file without losing all the
  422.      work done in the previous session.
  423.  
  424.      An error is signaled if there is no auto-save file for FILENAME,
  425.      or if FILENAME is newer than its auto-save file.  If FILENAME
  426.      does not exist, but its auto-save file does, then the auto-save
  427.      file is read as usual.  This last situation may occur if you
  428.      visited a nonexistent file and never actually saved it.
  429.  
  430.  
  431. 
  432. File: elisp,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
  433.  
  434. Buffers
  435. *******
  436.  
  437.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  438. are used to hold the contents of files that are being visited; there
  439. may also be buffers which are not visiting files.  While several
  440. buffers may exist at one time, exactly one buffer is designated the
  441. "current buffer" at any time.  Most editing commands act on the
  442. contents of the current buffer.  Each buffer, including the current
  443. buffer, may or may not be displayed in any windows.
  444.  
  445. * Menu:
  446.  
  447. * Buffer Basics::       What is a buffer?
  448. * Buffer Names::        Accessing and changing buffer names.
  449. * Buffer File Name::    The buffer file name indicates which file is visited.
  450. * Buffer Modification:: A buffer is "modified" if it needs to be saved.
  451. * Modification Time::   Determining whether the visited file was changed
  452.                          "behind Emacs's back".
  453. * Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
  454. * The Buffer List::     How to look at all the existing buffers.
  455. * Creating Buffers::    Functions that create buffers.
  456. * Killing Buffers::     Buffers exist until explicitly killed.
  457. * Current Buffer::      Designating a buffer as current
  458.                           so primitives will access its contents.
  459.  
  460.  
  461. 
  462. File: elisp,  Node: Buffer Basics,  Next: Buffer Names,  Prev: Buffers,  Up: Buffers
  463.  
  464. Buffer Basics
  465. =============
  466.  
  467.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  468. are used to hold the contents of files that are being visited; there
  469. may also be buffers which are not visiting files.  While several
  470. buffers may exist at one time, exactly one buffer is designated the
  471. "current buffer" at any time.  Most editing commands act on the
  472. contents of the current buffer.  Each buffer, including the current
  473. buffer, may or may not be displayed in any windows.
  474.  
  475.    Buffers in Emacs editing are objects which have distinct names and
  476. hold text that can be edited.  Buffers appear to Lisp programs as a
  477. special data type.  The contents of a buffer may be viewed as an
  478. extendible string; insertions and deletions may occur in any part of
  479. the buffer.  *Note Text::.
  480.  
  481.    A Lisp buffer object contains numerous pieces of information. 
  482. Some of this information is directly accessible to the programmer
  483. through variables, while other information is only accessible through
  484. special-purpose functions.  For example, the width of a tab character
  485. is directly accessible through a variable, while the value of point
  486. is accessible only through a primitive function.
  487.  
  488.    Buffer-specific information that is directly accessible is stored
  489. in "buffer-local" variable bindings, which are variable values that
  490. are effective only in a particular buffer.  This feature allows each
  491. buffer to override the values of certain variables.  Most major modes
  492. override variables such as `fill-column' or `comment-column' in this
  493. way.  For more information about buffer-local variables and functions
  494. related to them, see *Note Buffer-Local Variables::.
  495.  
  496.    For functions and variables related to visiting files in buffers,
  497. see *Note Visiting Files:: and *Note Saving Buffers::.  For functions
  498. and variables related to the display of buffers in windows, see *Note
  499. Buffers and Windows::.
  500.  
  501.  * Function: bufferp OBJECT
  502.      This function returns `t' if OBJECT is a buffer, `nil' otherwise.
  503.  
  504.  
  505. 
  506. File: elisp,  Node: Buffer Names,  Next: Buffer File Name,  Prev: Buffer Basics,  Up: Buffers
  507.  
  508. Buffer Names
  509. ============
  510.  
  511.    Each buffer has a unique name, which is a string.  The buffer name
  512. may be used in place of the buffer object in many functions that
  513. operate on buffers.  Buffers that are generally ephemeral and
  514. uninteresting to the user have names starting with a space, which
  515. prevents them from being listed by the `list-buffers' or
  516. `buffer-menu' commands.
  517.  
  518.    Many of the following functions accept either a buffer or a buffer
  519. name (a string) as an argument.  Any argument called BUFFER-OR-NAME
  520. is of this sort, and an error is signaled if it is neither a string
  521. nor a buffer.  Any argument called BUFFER is required to be an actual
  522. buffer object, not a name.
  523.  
  524.  * Function: buffer-name &optional BUFFER
  525.      This function returns the name of BUFFER as a string.  If BUFFER
  526.      is not supplied, it defaults to the current buffer.
  527.  
  528.      If `buffer-name' returns `nil', it means that BUFFER has been
  529.      killed.  *Note Killing Buffers::.
  530.  
  531.           (buffer-name)
  532.                => "buffers.texi"
  533.           
  534.           (setq foo (get-buffer "temp"))
  535.                => #<buffer temp>
  536.           (kill-buffer foo)
  537.                => nil
  538.           (buffer-name foo)
  539.                => nil
  540.           foo
  541.                => #<killed buffer>
  542.  
  543.  * Command: rename-buffer NEWNAME
  544.      This function renames the current buffer to NEWNAME.  An error
  545.      is signaled if NEWNAME is not a string, or if there is already a
  546.      buffer with that name.  The function returns `nil'.
  547.  
  548.      One application of this command is to rename the `*shell*'
  549.      buffer to some other name, thus making it possible to create a
  550.      second shell buffer under the name `*shell*'.
  551.  
  552.  * Function: get-buffer BUFFER-OR-NAME
  553.      This function returns the buffer specified by BUFFER-OR-NAME. 
  554.      If BUFFER-OR-NAME is a string and there is no buffer with that
  555.      name, the value is `nil'.  If BUFFER-OR-NAME is a buffer, it is
  556.      returned as given.  (That is not very useful, so the argument is
  557.      usually  a name.)  For example:
  558.  
  559.           (setq b (get-buffer "lewis"))
  560.                => #<buffer lewis>
  561.           (get-buffer b)
  562.                => #<buffer lewis>
  563.           (get-buffer "Frazzle-nots")
  564.                => nil
  565.  
  566.  
  567. 
  568. File: elisp,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
  569.  
  570. Buffer File Name
  571. ================
  572.  
  573.    The "buffer file name" is the name of the file that is visited in
  574. that buffer.  When a buffer is not visiting a file, its buffer file
  575. name is `nil'.  Most of the time, the buffer name is the same as the
  576. nondirectory part of the buffer file name, but the buffer file name
  577. and the buffer name are distinct and can be set independently.  *Note
  578. Visiting Files::.
  579.  
  580.  * Function: buffer-file-name &optional BUFFER
  581.      This function returns the absolute file name of the file that
  582.      BUFFER is visiting.  If BUFFER is not visiting any file,
  583.      `buffer-file-name' returns `nil'.  If BUFFER is not supplied, it
  584.      defaults to the current buffer.
  585.  
  586.           (buffer-file-name (other-buffer))
  587.                => "/usr/user/lewis/manual/files.texi"
  588.  
  589.  * Variable: buffer-file-name
  590.      This buffer-local variable contains the name of the file being
  591.      visited in the current buffer, or `nil' if it is not visiting a
  592.      file.
  593.  
  594.           buffer-file-name
  595.                => "/usr/user/lewis/manual/buffers.texi"
  596.  
  597.      It is risky to change this variable's value without doing
  598.      various other things.  See the definition of
  599.      `set-visited-file-name' in `files.el'; some of the things done
  600.      there, such as changing the buffer name, are not necessary, but
  601.      others are essential to avoid confusing Emacs.
  602.  
  603.  * Function: get-file-buffer FILENAME
  604.      This function returns the buffer visiting file FILENAME.  If
  605.      there is no such buffer, it returns `nil'.  The argument
  606.      FILENAME, which must be a string, is expanded (*note File Name
  607.      Expansion::.), then compared against the visited file names of
  608.      all live buffers.
  609.  
  610.           (get-file-buffer "buffers.texi")
  611.           => #<buffer buffers.texi>
  612.  
  613.      In unusual circumstances, there can be more than one buffer
  614.      visiting the same file name.  In such cases, this function
  615.      returns the first such buffer in the buffer list.
  616.  
  617.  * Command: set-visited-file-name FILENAME
  618.      If FILENAME is a non-empty string, this function changes the
  619.      name of the file visited in current buffer to FILENAME.  (If the
  620.      buffer had no visited file, this gives it one.)  The *next time*
  621.      the buffer is saved it will go in the newly-specified file.  The
  622.      buffer is always marked as modified, since it does not (as far
  623.      as Emacs knows) match the contents of FILENAME, even if it
  624.      matched the former visited file.
  625.  
  626.      If FILENAME is `nil' or the empty string, that stands for "no
  627.      visited file".  In this case, `set-visited-file-name' marks the
  628.      buffer as having no visited file.
  629.  
  630.      When `set-visited-file-name' is called interactively, it prompts
  631.      for FILENAME in the minibuffer.
  632.  
  633.      See also `clear-visited-file-modtime' and
  634.      `verify-visited-file-modtime' in *Note Buffer Modification::.
  635.  
  636.  
  637. 
  638. File: elisp,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
  639.  
  640. Buffer Modification
  641. ===================
  642.  
  643.    Emacs keeps a flag called the "modified flag" for each buffer, to
  644. record whether you have changed the text of the buffer.  This flag is
  645. set to `t' whenever you alter the contents of the buffer, and cleared
  646. to `nil' when you save it.  Thus, the flag shows whether there are
  647. unsaved changes.  The flag value is normally shown in the mode line
  648. (*note Mode Line Variables::.), and controls saving (*note Saving
  649. Buffers::.) and auto-saving (*note Auto-Saving::.).
  650.  
  651.    Some Lisp programs set the flag explicitly.  For example, the Lisp
  652. function `set-visited-file-name' sets the flag to `t', because the
  653. text does not match the newly-visited file, even if it is unchanged
  654. from the file formerly visited.
  655.  
  656.    The functions that modify the contents of buffers are described in
  657. *Note Text::.
  658.  
  659.  * Function: buffer-modified-p &optional BUFFER
  660.      This function returns `t' if the buffer BUFFER has been modified
  661.      since it was last read in from a file or saved, or `nil'
  662.      otherwise.  If BUFFER is not supplied, the current buffer is
  663.      tested.
  664.  
  665.  * Function: set-buffer-modified-p FLAG
  666.      This function marks the current buffer as modified if FLAG is
  667.      non-`nil', or as unmodified if the flag is `nil'.
  668.  
  669.      Another effect of calling this function is to cause
  670.      unconditional redisplay of the mode line for the current buffer.
  671.      In fact, the standard way to force redisplay of the mode line is
  672.      as follows:
  673.  
  674.           (set-buffer-modified-p (buffer-modified-p))
  675.  
  676.  * Command: not-modified
  677.      This command marks the current buffer as unmodified, and not
  678.      needing to be saved.  Don't use this function in programs, since
  679.      it prints a message; use `set-buffer-modified-p' (above) instead.
  680.  
  681.  
  682. 
  683. File: elisp,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
  684.  
  685. Comparison of Modification Time
  686. ===============================
  687.  
  688.    Suppose that you visit a file and make changes in its buffer, and
  689. meanwhile the file itself is changed on disk.  At this point, saving
  690. the buffer would overwrite the changes in the file.  Occasionally
  691. this may be what you want, but usually it would lose valuable
  692. information.  Emacs therefore checks the file's modification time
  693. using the functions described below before saving the file.
  694.  
  695.  * Function: verify-visited-file-modtime BUFFER
  696.      This function compares Emacs's record of the modification time
  697.      for the file that the buffer is visiting against the actual
  698.      modification time of the file as recorded by the operating
  699.      system.  The two will be the same unless some other process has
  700.      written the file since Emacs visited or saved it.
  701.  
  702.      The function returns `t' if the last actual modification time
  703.      and Emacs's recorded modification time are the same, `nil'
  704.      otherwise.
  705.  
  706.  * Function: clear-visited-file-modtime
  707.      This function clears out the record of the last modification
  708.      time of the file being visited by the current buffer.  As a
  709.      result, the next attempt to save this buffer will not complain
  710.      of a discrepancy in file modification times.
  711.  
  712.      This function is called in `set-visited-file-name' and other
  713.      exceptional places where the usual test to avoid overwriting a
  714.      changed file should not be done.
  715.  
  716.  * Function: ask-user-about-supersession-threat FN
  717.      This function is used to ask a user how to proceed after an
  718.      attempt to modify an obsolete buffer.  An "obsolete buffer" is
  719.      an unmodified buffer for which the associated file on disk is
  720.      newer than the last save-time of the buffer.  This means some
  721.      other program has probably altered the file.
  722.  
  723.      This function is called automatically by Emacs on the proper
  724.      occasions.  It exists so you can customize Emacs by redefining it.
  725.      See the file `userlock.el' for the standard definition.
  726.  
  727.      Depending on the user's answer, the function may return
  728.      normally, in which case the modification of the buffer proceeds,
  729.      or it may signal a `file-supersession' error with data `(FN)',
  730.      in which case the proposed buffer modification is not allowed.
  731.  
  732.      See also the file locking mechanism in *Note File Locks::.
  733.  
  734.  
  735. 
  736. File: elisp,  Node: Read Only Buffers,  Next: The Buffer List,  Prev: Modification Time,  Up: Buffers
  737.  
  738. Read-Only Buffers
  739. =================
  740.  
  741.    A buffer may be designated as "read-only".  This means that the
  742. buffer's contents may not be modified, although you may change your
  743. view of the contents by scrolling, narrowing, or widening, etc.
  744.  
  745.    Read-only buffers are used in two kinds of situations:
  746.  
  747.    * A buffer visiting a file is made read-only if the file is
  748.      write-protected.
  749.  
  750.      Here, the purpose is to show the user that editing the buffer
  751.      with the aim of saving it in the file may be futile or
  752.      undesirable.  The user who wants to change the buffer text
  753.      despite this can do so after clearing the read-only flag with
  754.      the function `toggle-read-only'.
  755.  
  756.    * Modes such as Dired and Rmail make buffers read-only when
  757.      altering the contents with the usual editing commands is
  758.      probably a mistake.
  759.  
  760.      The special commands of the mode in question bind
  761.      `buffer-read-only' to `nil' (with `let') around the places where
  762.      they change the text.
  763.  
  764.  * Variable: buffer-read-only
  765.      This buffer-local variable specifies whether the buffer is
  766.      read-only.  The buffer is read-only if this variable is non-`nil'.
  767.  
  768.  * Command: toggle-read-only
  769.      This command changes whether the current buffer is read-only. 
  770.      It is intended for interactive use; don't use it in programs. 
  771.      At any given point in a program, you should know whether you
  772.      want the read-only flag on or off; so you can set
  773.      `buffer-read-only' explicitly to the proper value, `t' or `nil'.
  774.  
  775.  * Function: barf-if-buffer-read-only
  776.      This function signals a `buffer-read-only' error if the current
  777.      buffer is read-only.  *Note Interactive Call::, for another way
  778.      to signal an error if the current buffer is read-only.
  779.  
  780.  
  781. 
  782. File: elisp,  Node: The Buffer List,  Next: Creating Buffers,  Prev: Read Only Buffers,  Up: Buffers
  783.  
  784. The Buffer List
  785. ===============
  786.  
  787.    The "buffer list" is a list of all buffers that have not been
  788. killed.  The order of the buffers in the list is based primarily on
  789. how recently each buffer has been displayed in the selected window. 
  790. Several functions, notably `other-buffer', make use of this ordering.
  791.  
  792.  * Function: buffer-list
  793.      This function returns a list of all buffers, including those
  794.      whose names begin with a space.  The elements are actual
  795.      buffers, not their names.
  796.  
  797.           (buffer-list)
  798.                => (#<buffer buffers.texi> #<buffer  *Minibuf-1*>
  799.                    #<buffer buffer.c>  #<buffer *Help*> #<buffer TAGS>)
  800.           
  801.           ;; Note that the name of the minibuffer begins with a space!
  802.           
  803.           (mapcar (function buffer-name) (buffer-list))
  804.           => ("buffers.texi" " *Minibuf-1*" "buffer.c" "*Help*" "TAGS")
  805.  
  806.      This list is a copy of a list used inside Emacs; modifying it
  807.      has no effect on the buffers.
  808.  
  809.  * Function: other-buffer &optional BUFFER-OR-NAME
  810.      This function returns the first buffer in the buffer list other
  811.      than BUFFER-OR-NAME.  Usually this is the buffer most recently
  812.      shown in the selected window, aside from BUFFER-OR-NAME. 
  813.      Buffers are moved to the front of the list when they are
  814.      selected and to the end when they are buried.  Buffers whose
  815.      names start with a space are not even considered.
  816.  
  817.      If BUFFER-OR-NAME is not supplied (or if it is not a buffer),
  818.      then `other-buffer' returns the first buffer on the buffer list
  819.      that is not visible in any window.
  820.  
  821.      If no suitable buffer exists, the buffer `*scratch*' is returned
  822.      (and created, if necessary).
  823.  
  824.  * Command: list-buffers &optional FILES-ONLY
  825.      This function displays a listing of the names of existing
  826.      buffers.  It clears the buffer `*Buffer List*', then inserts the
  827.      listing into that buffer and displays it in a window. 
  828.      `list-buffers' is intended for interactive use, and is described
  829.      fully in ``The GNU Emacs Manual''.  It returns `nil'.
  830.  
  831.  * Command: bury-buffer &optional BUFFER-OR-NAME
  832.      This function puts BUFFER-OR-NAME at the end of the buffer list
  833.      without changing the order of any of the other buffers on the
  834.      list.  This buffer therefore becomes the least desirable
  835.      candidate for `other-buffer' to return, and appears last in the
  836.      list displayed by `list-buffers'.
  837.  
  838.      If BUFFER-OR-NAME is the current buffer, then it is replaced in
  839.      the selected window by the buffer chosen using `other-buffer'. 
  840.      If the buffer is displayed in a window other than the selected
  841.      one, it remains there.
  842.  
  843.      If BUFFER-OR-NAME is not supplied, it defaults to the current
  844.      buffer.  This is what happens in an interactive call.
  845.  
  846.  
  847. 
  848. File: elisp,  Node: Creating Buffers,  Next: Killing Buffers,  Prev: The Buffer List,  Up: Buffers
  849.  
  850. Creating Buffers
  851. ================
  852.  
  853.    This section describes the two primitives for creating buffers. 
  854. `get-buffer-create' creates a buffer if it finds no existing buffer;
  855. `generate-new-buffer' always creates a new buffer, and gives it a
  856. unique name.
  857.  
  858.    Two other functions to create buffers are
  859. `with-output-to-temp-buffer' (*note Temporary Displays::.) and
  860. `create-file-buffer' (*note Visiting Files::.).
  861.  
  862.  * Function: get-buffer-create NAME
  863.      This function returns a buffer named NAME.  If such a buffer
  864.      already exists, it is returned.  If such a buffer does not
  865.      exist, one is created and returned.  The buffer does not become
  866.      the current buffer--this function does not change which buffer
  867.      is current.
  868.  
  869.      An error is signaled if NAME is not a string.
  870.  
  871.           (get-buffer-create "foo")
  872.                => #<buffer foo>
  873.  
  874.      The major mode for the new buffer is chosen according to the
  875.      value of `default-major-mode'.  *Note Auto Major Mode::.
  876.  
  877.  * Function: generate-new-buffer NAME
  878.      This function returns a newly created, empty buffer.  If there
  879.      is no buffer named NAME, then that is the name of the new
  880.      buffer.  If there is a buffer with that name, then suffixes of
  881.      the form `<N>' are added to NAME, where N stands for successive
  882.      integers starting with 2.  New suffixes are tried until an
  883.      unused name is found.
  884.  
  885.      An error is signaled if NAME is not a string.
  886.  
  887.           (generate-new-buffer "bar")
  888.                => #<buffer bar>
  889.           (generate-new-buffer "bar")
  890.                => #<buffer bar<2>>
  891.           (generate-new-buffer "bar")
  892.                => #<buffer bar<3>>
  893.  
  894.      The major mode for the new buffer is chosen according to the
  895.      value of `default-major-mode'.  *Note Auto Major Mode::.
  896.  
  897.  
  898. 
  899. File: elisp,  Node: Killing Buffers,  Next: Current Buffer,  Prev: Creating Buffers,  Up: Buffers
  900.  
  901. Killing Buffers
  902. ===============
  903.  
  904.    "Killing a buffer" makes its name unknown to Emacs and makes its
  905. space available for other use.
  906.  
  907.    The buffer object for the buffer which has been killed remains in
  908. existence as long as anything refers to it, but it is specially
  909. marked so that you cannot make it current or display it.  Killed
  910. buffers retain their identity, however; two distinct buffers, when
  911. killed, remain distinct according to `eq'.
  912.  
  913.    The `buffer-name' of a killed buffer is `nil'.  You can use this
  914. feature to test whether a buffer has been killed:
  915.  
  916.      (defun killed-buffer-p (buffer)
  917.        "Return t if BUFFER is killed."
  918.        (not (buffer-name buffer)))
  919.  
  920.  * Command: kill-buffer BUFFER-OR-NAME
  921.      This function kills the buffer BUFFER-OR-NAME, freeing all its
  922.      memory for use as space for other buffers.  (In Emacs version
  923.      18, the memory is not returned to the operating system.)  It
  924.      returns `nil'.
  925.  
  926.      Any processes that have this buffer as the `process-buffer' are
  927.      sent the `SIGHUP' signal, which normally causes them to terminate.
  928.      (The usual meaning of `SIGHUP' is that a dialup line has been
  929.      disconnected.)  *Note Deleting Processes::.
  930.  
  931.      If the buffer is visiting a file when `kill-buffer' is called
  932.      and the buffer has not been saved since it was last modified,
  933.      the user is asked to confirm before the buffer is killed.  This
  934.      is done even if `kill-buffer' is not called interactively.  To
  935.      prevent the request for confirmation, clear the modified flag
  936.      before calling `kill-buffer'.  *Note Buffer Modification::.
  937.  
  938.           (kill-buffer "foo.unchanged")
  939.                => nil
  940.           (kill-buffer "foo.changed")
  941.           
  942.           ---------- Buffer: Minibuffer ----------
  943.           Buffer foo.changed modified; kill anyway? (yes or no) `yes'
  944.           ---------- Buffer: Minibuffer ----------
  945.           
  946.                => nil
  947.  
  948.  
  949. 
  950. File: elisp,  Node: Current Buffer,  Prev: Killing Buffers,  Up: Buffers
  951.  
  952. The Current Buffer
  953. ==================
  954.  
  955.    There are in general many buffers in an Emacs session.  At any
  956. time, one of them is designated as the "current buffer".  This is the
  957. buffer in which most editing takes place, because most of the
  958. primitives for examining or changing text in a buffer operate
  959. implicitly on the current buffer (*note Text::.).  Normally the
  960. buffer that is displayed on the screen in the selected window is the
  961. current buffer, but this is not always so: a Lisp program can
  962. designate any buffer as current temporarily in order to operate on
  963. its contents, without changing what is displayed on the screen.
  964.  
  965.    The way to designate a current buffer in a Lisp program is by
  966. calling `set-buffer'.  The specified buffer remains current until a
  967. new one is designated.
  968.  
  969.    When an editing command returns to the editor command loop, the
  970. command loop designates the buffer displayed in the selected window
  971. as current, to prevent confusion: the buffer that the cursor is in,
  972. when Emacs reads a command, is the one to which the command will apply.
  973. (*Note Command Loop::.)  Therefore, `set-buffer' is not usable for
  974. switching visibly to a different buffer so that the user can edit it.
  975. For this, you must use the functions described in *Note Displaying
  976. Buffers::.
  977.  
  978.    However, Lisp functions that change to a different current buffer
  979. should not rely on the command loop to set it back afterwards. 
  980. Editing commands written in Emacs Lisp can be called from other
  981. programs as well as from the command loop.  It is convenient for the
  982. caller if the subroutine does not change which buffer is current
  983. (unless, of course, that is the subroutine's purpose).  Therefore,
  984. you should normally use `set-buffer' within a `save-excursion' that
  985. will restore the current buffer when your program is done (*note
  986. Excursions::.).  Here is an example, the code for the command
  987. `append-to-buffer' (with the documentation string abridged):
  988.  
  989.      (defun append-to-buffer (buffer start end)
  990.        "Append to specified buffer the text of the region..."
  991.        (interactive "BAppend to buffer: \nr")
  992.        (let ((oldbuf (current-buffer)))
  993.          (save-excursion
  994.            (set-buffer (get-buffer-create buffer))
  995.            (insert-buffer-substring oldbuf start end))))
  996.  
  997. In this function, a local variable is bound to the current buffer,
  998. and then `save-excursion' records the values of point, the mark, and
  999. the original buffer.  Next, `set-buffer' makes another buffer current.
  1000. Finally, `insert-buffer-substring' copies the string from the
  1001. original current buffer to the new current buffer.
  1002.  
  1003.    If the buffer appended to happens to be displayed in some window,
  1004. then the next redisplay will show how its text has changed. 
  1005. Otherwise, you will not see the change immediately on the screen. 
  1006. The buffer becomes current temporarily during the execution of the
  1007. command, but this does not cause it to be displayed.
  1008.  
  1009.  * Function: current-buffer
  1010.      This function returns the current buffer.
  1011.  
  1012.           (current-buffer)
  1013.                => #<buffer buffers.texi>
  1014.  
  1015.  * Function: set-buffer BUFFER-OR-NAME
  1016.      This function makes BUFFER-OR-NAME the current buffer.  However,
  1017.      it does not display the buffer in the currently selected window
  1018.      or in any other window.  This means that the user cannot
  1019.      necessarily see the buffer, but Lisp programs can in any case
  1020.      work on it.
  1021.  
  1022.      This function returns the buffer identified by BUFFER-OR-NAME. 
  1023.      An error is signaled if BUFFER-OR-NAME does not identify an
  1024.      existing buffer.
  1025.  
  1026.  
  1027. 
  1028. File: elisp,  Node: Windows,  Next: Positions,  Prev: Buffers,  Up: Top
  1029.  
  1030. Windows
  1031. *******
  1032.  
  1033.    This chapter describes most of the functions and variables related
  1034. to Emacs windows.  See *Note Emacs Display::, for information on how
  1035. text is displayed in windows.
  1036.  
  1037. * Menu:
  1038.  
  1039. * Basic Windows::          Basic information on using windows.
  1040. * Splitting Windows::      Splitting one window into two windows.
  1041. * Deleting Windows::       Deleting a window gives its space to other windows.
  1042. * Selecting Windows::      The selected window is the one that you edit in.
  1043. * Cyclic Window Ordering:: Moving around the existing windows.
  1044. * Buffers and Windows::    Each window displays the contents of a buffer.
  1045. * Displaying Buffers::     Higher-lever functions for displaying a buffer
  1046.                              and choosing a window for it.
  1047. * Window Point::           Each window has its own location of point.
  1048. * Window Start::           The display-start position controls which text
  1049.                              is on-screen in the window. 
  1050. * Vertical Scrolling::     Moving text up and down in the window.
  1051. * Horizontal Scrolling::   Moving text sideways on the window.
  1052. * Size of Window::         Accessing the size of a window.
  1053. * Resizing Windows::       Changing the size of a window.
  1054. * Window Configurations::  Saving and restoring the state of the screen.
  1055.  
  1056.  
  1057. 
  1058. File: elisp,  Node: Basic Windows,  Next: Splitting Windows,  Prev: Windows,  Up: Windows
  1059.  
  1060. Basic Concepts of Emacs Windows
  1061. ===============================
  1062.  
  1063.    A "window" is the physical area of the screen in which a buffer is
  1064. displayed.  The term is also used to refer to a Lisp object which
  1065. represents that screen area in Emacs Lisp.  It should be clear from
  1066. the context which is meant.
  1067.  
  1068.    There is always at least one window displayed on the screen, and
  1069. there is exactly one window that we call the "selected window".  The
  1070. cursor is in the selected window.  The selected window's buffer is
  1071. usually the current buffer (except when `set-buffer' has been used.) 
  1072. *Note Current Buffer::.
  1073.  
  1074.    For all intents, a window only exists while it is displayed on the
  1075. terminal.  Once removed from the display, the window is effectively
  1076. deleted and should not be used, *even though there may still be
  1077. references to it* from other Lisp objects.  (*Note Deleting Windows::.)
  1078.  
  1079.    Each window has the following attributes:
  1080.  
  1081.    * window height
  1082.  
  1083.    * window width
  1084.  
  1085.    * window edges with respect to the screen
  1086.  
  1087.    * the buffer it displays
  1088.  
  1089.    * position within the buffer at the upper left of the window
  1090.  
  1091.    * the amount of horizontal scrolling, in columns
  1092.  
  1093.    * point
  1094.  
  1095.    * the mark
  1096.  
  1097.    * how recently the window was selected
  1098.  
  1099.    Applications use multiple windows for a variety of reasons, but
  1100. most often to give different views of the same information.  In
  1101. Rmail, for example, you can move through a summary buffer in one
  1102. window while the other window shows messages one at a time as they
  1103. are reached.
  1104.  
  1105.    Use of the word "window" to refer to a view of a buffer was
  1106. established long ago in Emacs.  The metaphor was inspired by how you
  1107. look out a house window--at part (or sometimes all) of an overall view.
  1108. You see part (or sometimes all) of a buffer through an Emacs window. 
  1109. In Emacs, each window may look on a different view, like different
  1110. windows of a house.
  1111.  
  1112.    The term "window" as used in this manual means something different
  1113. from the term as used in a window system like X Windows.  In this
  1114. manual, the term "window" refers to the nonoverlapping subdivisions
  1115. of the Emacs display.  If Emacs is displaying on a window system, the
  1116. Emacs display may itself be one X window among many on the screen. 
  1117. But Emacs version 18 knows nothing of this.
  1118.  
  1119.    For those familiar with windowing systems, Emacs's windows are
  1120. rectangles tiled onto the rectangle of the screen, and every portion
  1121. of the screen is part of some window, except (sometimes) the
  1122. minibuffer area.  This limitation helps avoid wasting the
  1123. historically scarce resource of screen space.  It also works well
  1124. with character-only terminals.  Because of the way in which Emacs
  1125. creates new windows and resizes them, you can't create every
  1126. conceivable tiling on an Emacs screen.  *Note Splitting Windows::. 
  1127. Also, see *Note Size of Window::.
  1128.  
  1129.    *Note Emacs Display::, for information on how the contents of the
  1130. window's buffer are displayed in the window.
  1131.  
  1132.  * Function: windowp OBJECT
  1133.      This function returns `t' if OBJECT is a window.
  1134.  
  1135.  
  1136.